<?php


namespace partner\functions\wechat\lib;


use partner\functions\wechat\lib\BaseWechatPartner;
use Exception;
use partner\functions\wechat\lib\SaleInfo\AppInfo;
use partner\functions\wechat\lib\SaleInfo\BizStoreInfo;
use partner\functions\wechat\lib\SaleInfo\MiniProgramInfo;
use partner\functions\wechat\lib\SaleInfo\MpInfo;
use partner\functions\wechat\lib\SaleInfo\WebInfo;
use partner\functions\wechat\lib\SaleInfo\WeWorkInfo;

class SaleInfo extends BaseWechatPartner
{
    protected $desensitization_properties = [
        'contact_name',
        'contact_id_number',
        'ubo_id_doc_address',
        'openid',
        'mobile_phone',
        'contact_email'
    ];

    protected $upload_properties = [
        'contact_id_doc_copy' => 1,
        'contact_id_doc_copy_back' => 1,
        'business_authorization_letter' => 1
    ];
    
    // 合法的经营场景类型
    private $allowd_sales_scenes_type = [
        'SALES_SCENES_STORE', 
        'SALES_SCENES_MP', 
        'SALES_SCENES_MINI_PROGRAM',
        'SALES_SCENES_WEB', 
        'SALES_SCENES_APP', 
        'SALES_SCENES_WEWORK'
    ];

    // 经营场景类型
    public $sales_scenes_type = [];

    // 线下场所场景
    public $biz_store_info;

    // 公众号场景
    public $mp_info;

    // 小程序场景
    public $mini_program_info;

    // App场景
    public $app_info;

    // 互联网网站场景
    public $web_info;

    // 企业微信场景
    public $we_work_info;

    public function setSalesScenesType(array $sales_scenes_type = [])
    {
        if (empty($sales_scenes_type))
            throw new Exception("经营场景类型不能为空");
        
        foreach($sales_scenes_type as $sales_scene_type) {
            if (! in_array($sales_scene_type, $this->allowd_sales_scenes_type))
                throw new Exception("非法经营场景类型");
        }
        return $this;
    }    

    public function getAllowedSalesScenesType()
    {
        return $this->allowd_sales_scenes_type;
    }

    public function setBizStoreInfo(BizStoreInfo $biz_store_info) 
    {
        $this->biz_store_info = $biz_store_info;
        return $this;
    }

    public function setMpInfo(MpInfo $mp_info) 
    {
        $this->mp_info = $mp_info;
        return $this;
    }

    public function setMiniProgramInfo(MiniProgramInfo $mini_program_info) 
    {
        $this->mini_program_info = $mini_program_info;
        return $this;
    }

    public function setAppInfo(AppInfo $app_info) 
    {
        $this->app_info = $app_info;
        return $this;
    }

    public function setWebInfo(WebInfo $web_info)
    {
        $this->web_info = $web_info;
        return $this;
    }

    public function setWeWorkInfo(WeWorkInfo $we_work_info)
    {
        $this->we_work_info = $we_work_info;
        return $this;
    }
}